package com.chenliang.nacosconfig;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;

import java.util.concurrent.TimeUnit;

/**
 * @program: springcloud_all
 * @description:
 * @author: 陈亮
 * @create: 2022-04-07 23:46
 */
@SpringBootApplication
public class NacosConfigApplication {


    public static void main(String[] args) throws InterruptedException {
        ConfigurableApplicationContext context = SpringApplication.run(NacosConfigApplication.class, args);

        while(true) {
            //当动态配置刷新时，会更新到 Enviroment中，因此这里每隔一秒中从Enviroment中获取配置
            String userName = context.getEnvironment().getProperty("user.name");
            String userAge = context.getEnvironment().getProperty("user.age");
            String env = context.getEnvironment().getProperty("env");
            System.err.println("输出---->userName:"+userName+",userAge:"+userAge+",env:"+env);
            TimeUnit.SECONDS.sleep(7);
        }
    }
}
